using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class PurchaseRequsitionDetailMap : EntityTypeConfiguration<PurchaseRequsitionDetail>
	{
		public PurchaseRequsitionDetailMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.SupplierCode)
				.HasMaxLength(50);
				
			this.Property(t => t.ItemCode)
				.HasMaxLength(10);
				
			// Table & Column Mappings
			this.ToTable("PurchaseRequsitionDetails");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.PurchaseRequsitionId).HasColumnName("PurchaseRequsitionId");
			this.Property(t => t.SupplierCode).HasColumnName("SupplierCode");
			this.Property(t => t.ItemCode).HasColumnName("ItemCode");
			this.Property(t => t.Qty).HasColumnName("Qty");
			this.Property(t => t.UnitOfMeasurementType).HasColumnName("UnitOfMeasurementType");

			// Relationships
			this.HasOptional(t => t.PurchaseRequsition)
				.WithMany(t => t.PurchaseRequsitionDetails)
				.HasForeignKey(d => d.PurchaseRequsitionId);
				
			this.HasOptional(t => t.RefUomType)
				.WithMany(t => t.PurchaseRequsitionDetails)
				.HasForeignKey(d => d.UnitOfMeasurementType);
				
		}
	}
}

